import React, { Component } from 'react'

export default class child extends Component {
  constructor () {
    super()
    this.state = {
      position: {
        x: 0,
        y: 0
      }
    }
  }
  move = e => {
    console.log(e)
    this.setState({
      position: {
        x: e.clientX,
        y: e.clientY
      }
    })
  }
  componentDidMount () {
    window.addEventListener('mousemove', this.move)
  }
  componentWillUnmount () {
    window.removeEventListener('mousemove', this.move)
  }
  render () {
    return <div>{this.props.children(this.state.position)}</div>
  }
}
